// pages/me_content/discount.js
import { getUserGiftList } from "../api/index";
import { store } from "../../store/index";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageData: {
      pageNo: 1,
      pageSize: 10,
      list: [],
    },
    type: '',
    total: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, "optionsoptions");
    if (options.type) {
      this.setData({
        type: options.type,
      });
    }

    this.getDiscountList();
  },
  getDiscountList() {
    getUserGiftList({
      pageNo: this.data.pageData.pageNo,
      pageSize: this.data.pageData.pageSize,
    }).then((res) => {
      const {records, total} = res.result;
      console.log(res, "res");
      this.setData({
        pageData: {
          ...this.data.pageData,
          list: this.data.pageData.list.concat(records),
        },
        total,
      });
    });
  },
  handleSelectCoupon(e) {
    if (this.data.type === 'select') {
      const item = e.currentTarget.dataset.item;
      store.updateSelectCoupon(item);
      wx.navigateBack();
    }
  },
});
